<script setup>
  import { ref, onMounted } from 'vue'
  import messageApi from '@/apis/message'

  // 任务列表数据
  const notifyList = ref([])
  // 下一页页码
  const nextPage = ref(1)
  // 每页包含数据条数
  const pageSize = ref(5)
  // 是否为空列表
  const isEmpty = ref(false)

  // 生命周期
  onMounted(() => {
    getNotifyList()
  })
  async function getNotifyList(contentType = 201) {
    try {
      let { code, msg, data } = await messageApi.getList(contentType)
      if (code !== 200) return uni.utils.toast('获取通知失败，稍后重试!')

      notifyList.value = data.items
    } catch (err) {}
  }
  // 上拉分页
  function onScrollToLower() {
    getNotifyList()
  }
  // 下拉刷新
  async function onScrollViewRefresh() {
    await getNotifyList()
  }
</script>
<template>
  <scroll-view
    @refresherrefresh="onScrollViewRefresh"
    @scrolltolower="onScrollToLower"
    class="scroll-view"
    refresher-enabled
    scroll-y
  >
    <view class="scroll-view-wrapper">
      <view class="message-action">
        <text class="iconfont icon-clear"></text>
        全部已读
      </view>
      <uni-card
        v-for="item in notifyList"
        :key="item.id"
        :border="false"
        :is-shadow="false"
      >
        <view class="brief">{{ item.content }}</view>
        <view class="extra">
          <text class="time">{{ item.created }}</text>
          <navigator
            hover-class="none"
            class="link"
            :url="`/subpkg_task/detail/index?id=${item.relevantId}`"
            >查看详情</navigator
          >
        </view>
        <template v-slot:title>
          <view class="title unread">您有新的运输任务</view>
        </template>
      </uni-card>
      <view v-if="notifyList.length == 0" class="message-blank">暂无消息</view>
    </view>
  </scroll-view>
</template>

<style lang="scss" scoped>
  @import './styles.scss';
</style>
